/*
 * Created by JFormDesigner on Wed Aug 21 15:24:30 CST 2019
 */

package com.zzq.test.ui;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;

/**
 * @author zzq
 */
public class Window extends JFrame {
    public Window() {
        initComponents();
    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        JFileChooser chooser = new JFileChooser();
        //设置选择目录
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        int reg = chooser.showOpenDialog(this);
//        if (reg == JFileChooser.APPROVE_OPTION) {
//            //获得选择到的文件
//            File file = chooser.getSelectedFile();
//            //加载文件
//            loadDir(file);
//        }

    }

    //加载列表项目录及文件
//    public void loadDir(File file) {
//        textField.setText(file.getAbsolutePath());
//        listmodel.clear();
//        //先添加一个目录
//        File parent = file.getParentFile();
//        if (parent != null) {
//            FileListItem item = new FileListItem(parent);
//            item.name = "返回上一级目录";
//            item.isDir = true;
//            listmodel.addElement(item);
//        }
//
//        File[] files = file.listFiles();
//        if (files != null) {
//            //将目录添加到前面
//            for (File f : files) {
//                FileListItem item = new FileListItem(f);
//                if (item.isDir)
//                    listmodel.addElement(item);
//                else
//                    continue;
//            }
//            //将文件添加到后面
//            for (File f : files) {
//                FileListItem item = new FileListItem(f);
//                if (!item.isDir)
//                    listmodel.addElement(item);
//                else
//                    continue;
//            }
//        }
//    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - unknown
        button1 = new JButton();

        //======== this ========
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- button1 ----
        button1.setText("1111");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(145, 130, 140, 30);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - unknown
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
